﻿<!DOCTYPE html>
<html ng-app="demoApp" lang="en">
<head>
    <title id='Description'>In this example is demonstrated the auto-complete feature of jqxComboBox. Suggestions are displayed when at least two characters are entered into the field.</title>
    <meta name="description" content="AngularJS ComboBox example. This example demonstrates a Remote Searching ComboBox built with Angular JS." />
    <link rel="stylesheet" href="../../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../../scripts/angular.min.js"></script>
    <script type="text/javascript" src="../../../scripts/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxcombobox.js"></script>
    <script type="text/javascript" src="../../../scripts/demos.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxangular.js"></script>
    <script type="text/javascript">
        var demoApp = angular.module("demoApp", ["jqwidgets"]);
        demoApp.controller("demoController", function ($scope)
        {
            // prepare the data
            var source =
            {
                datatype: "jsonp",
                datafields: [
                    { name: 'countryName' },
                    { name: 'name' },
                    { name: 'population', type: 'float' },
                    { name: 'continentCode' },
                    { name: 'adminName1' }
                ],
                url: "http://api.geonames.org/searchJSON",
                data: {
                    featureClass: "P",
                    style: "full",
                    maxRows: 12,
                    username: "jqwidgets"
                }
            };

            $scope.comboBox = {};

            var dataAdapter = new $.jqx.dataAdapter(source,
                {
                    formatData: function (data)
                    {
                        if ($scope.comboBox.searchString != undefined)
                        {
                            data.name_startsWith = $scope.comboBox.searchString;
                            return data;
                        }
                    }
                }
            );

            $scope.settings =
            {
                width: 250,
                height: 25,
                source: dataAdapter,
                remoteAutoComplete: true,
                autoDropDownHeight: true,
                created: function (args)
                {
                    $scope.comboBox = args.instance;
                },
                selectedIndex: 0,
                displayMember: "name",
                valueMember: "countryName",
                renderer: function (index, label, value)
                {
                    var item = dataAdapter.records[index];
                    if (item != null)
                    {
                        var label = item.name + "(" + item.countryName + ", " + item.adminName1 + ")";
                        return label;
                    }
                    return "";
                },
                renderSelectedItem: function (index, item)
                {
                    var item = dataAdapter.records[index];
                    if (item != null)
                    {
                        var label = item.name;
                        return label;
                    }
                    return "";
                },
                search: function (searchString)
                {
                    dataAdapter.dataBind();
                }
            }
        });
    </script>
</head>
<body ng-controller="demoController">
    <span>Search for a City:</span>
    <jqx-combo-box style="margin-top: 7px; margin-bottom: 5px;" jqx-settings="settings"></jqx-combo-box>
    <span>ex: be</span>
</body>
</html>
